//购物车的抛物线特效

define(function(require,exports,module){
function parabola(startPoint,endPoint,url,func){
	let imgDom  =document.createElement("img");
	imgDom.src=url;
	imgDom.style.cssText = "position:absolute;width:30px;height:30px;left:"+startPoint.x+"px;top:"+startPoint.y+"px;border-radius:50%";
	document.body.appendChild(imgDom);
	var myTimer=null;
	let x = 0;
	let incX = 3;
	let tempPoint = {x:endPoint.x-startPoint.x,y:endPoint.y-startPoint.y};
	let p = (tempPoint.y*tempPoint.y)/(2*tempPoint.x);
	
	(function(){
		if(myTimer!=null){
			window.clearInterval(myTimer);
		}
		myTimer = setInterval(function(){
			x=x+incX;
			if(x>endPoint.x-startPoint.x){
				imgDom.parentNode.removeChild(imgDom);
				window.clearInterval(myTimer);
				myTimer = null;
				func();
				return;
			}
			y = -1*Math.sqrt(2*p*x);
			let xTemp = x+startPoint.x;
			let yTemp = y+startPoint.y;
			imgDom.style.left = xTemp+"px";
			imgDom.style.top = yTemp+"px";			
		},1);
	})();
}

exports.parabola=parabola;	
});
	

